
package de.swta.freezay.database.wicketAdapter;

import de.swta.freezay.database.JPAController;
import java.util.Iterator;
import de.swta.freezay.database.dbEntities.Package;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

/**
 * A SortableDataProvider for package entities  (ADMIN VIEW!)
 *
 * @author Christian Baeumer
 * @see SortableDataProvider
 */
public class PackageDataProviderAdmin extends SortableDataProvider<Package>  {

    public PackageDataProviderAdmin() {
        /* set up default sorting */
        setSort("name", true);
    }

    @Override
    public Iterator<? extends Package> iterator(int first, int count) {
        
        final SortParam sp = getSort();

        return JPAController.PackageJpaController.findPackageEntitiesAdmin(
                count, first, sp.getProperty(), sp.isAscending()).iterator();
    }

    @Override
    public int size() {
        return JPAController.PackageJpaController.getPackageCountAdmin();
    }

    @Override
    public IModel<Package> model(Package p) {
        return new DetachablePackageModel(p);
    }

    @Override
    public void detach() {
    }

}
